package com.cc2019.buke.home.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.cc2019.buke.R;
import com.cc2019.buke.home.entry.Channel;

import java.util.List;

public class ProChannelAdapter extends RecyclerView.Adapter {
    List<Channel> pro_list;
    Context context;
    public ProChannelAdapter(List<Channel> pro_list,Context context){
        this.pro_list = pro_list;
        this.context = context;
    }
    class ChanHolder extends RecyclerView.ViewHolder{
        ImageView imageView;
        TextView nameView;
        TextView dataView;

        public ChanHolder(@NonNull View itemView) {
            super(itemView);
            imageView = itemView.findViewById(R.id.ch1_img);
            nameView = itemView.findViewById(R.id.chl_name);
            dataView = itemView.findViewById(R.id.chl_data);
        }
    }
    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.prochanlayout,parent,false);
        ChanHolder chanHolder = new ChanHolder(view);
        return chanHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
         Channel channel = pro_list.get(position);
         ChanHolder chanHolder = (ChanHolder)holder;
         chanHolder.imageView.setImageResource(channel.getImgid());
         chanHolder.nameView.setText(channel.getName());
         chanHolder.dataView.setText(channel.getData()+"万本+");
    }

    @Override
    public int getItemCount() {
        return pro_list.size();
    }
}
